#include <buola/image/format.h>
#include <buola/image/io.h>
#include <buola/image/drawing/basic.h>
#include <buola/image/adaptors.h>
#include <buola/image/views/cmaskedview.h>

using namespace buola;

int main()
{
    img::CImage_rgb8 lImage({320,200},img::pixel(255,255,255));
    img::CImage_gray8 lAlpha({320,200});

    for(int i=0;i<lAlpha.Height();i++)
    {
        uint8_t lValue=255*i/(lAlpha.Height()-1);
        img::fill_hline(lAlpha,0,i,lAlpha.Width(),lValue);
    }

    img::CPixel_rgb8 lSpan[320];

    for(int i=0;i<lImage.Width();i++)
    {
        lSpan[i]=img::CColor(img::nWaveLength,380.0+400.0*i/lImage.Width(),0.8);
    }

    auto lMaskedView=masked_view(lImage,lAlpha);

    start_timer();
    for(int j=0;j<20000;j++)
    for(int i=0;i<lImage.Height();i++)
    {
        img::fill_hspan(lMaskedView,0,i,lMaskedView.Width(),lSpan);
    }
    end_timer();

    img::save(lImage,io::file("agg4.ppm"));
}
